package com.huawei.appgallery.forum.section.view.widget;

import android.content.Context;
import android.text.TextUtils.TruncateAt;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.TabHost;
import android.widget.TextView;
import androidx.annotation.Nullable;
import com.huawei.appgallery.forum.base.card.bean.Options;
import com.huawei.appgallery.forum.base.card.bean.Options.OptionItem;
import com.huawei.appgallery.forum.base.https.jgw.JGWTabInfo;
import com.huawei.appgallery.forum.cards.widget.SpinnerAdapter;
import com.huawei.appgallery.foundation.ui.css.CSSRule;
import com.huawei.appgallery.foundation.ui.css.CSSViewProxy;
import com.huawei.appgallery.foundation.ui.css.RenderListener;
import com.huawei.appgallery.foundation.ui.css.adapter.CSSPropertyName;
import com.huawei.appgallery.foundation.ui.css.adapter.type.CSSMonoColor;
import com.huawei.appgallery.foundation.ui.css.adapter.type.CSSValue;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import o.azb;
import o.cab.b;
import o.cab.e;
import o.cab.i;
import o.cat;
import o.caw;
import o.cjz;
import o.epo;
import o.epv;
import o.erq;
import o.fo;

public class SectionDetailSubHead extends LinearLayout implements OnClickListener, caw, RenderListener {
    private static int ॱॱ = 0;
    private int ʻ = 0;
    private int ʼ;
    private LinearLayout ʽ;
    protected List<JGWTabInfo> ˊ;
    private boolean ˊॱ = false;
    protected List<c> ˋ = new ArrayList();
    protected SectionDetailSpinner ˎ;
    protected boolean ˏ = true;
    private d ˏॱ;
    protected SpinnerAdapter ॱ;
    private TabHost ॱˊ;
    private int ᐝ;

    public interface d {
        void ॱ(String str, String str2);
    }

    public static class c {
        private String ˊ;
        private int ˋ;
        private int ˎ = -1;
        private TextView ˏ;
        private String ॱ;

        public int ˋ() {
            return this.ˎ;
        }

        public void ˋ(int i) {
            this.ˎ = i;
        }

        public c(Context context, String str, String str2, int i) {
            this.ˊ = str;
            this.ॱ = str2;
            this.ˋ = i;
            this.ˏ = new TextView(context);
            this.ˏ.setText(str2);
            this.ˏ.setTag(this);
            ˎ(context, i, this.ˏ);
        }

        public TextView ॱ() {
            return this.ˏ;
        }

        public int ˊ() {
            return this.ˋ;
        }

        private void ˎ(Context context, int i, TextView textView) {
            LayoutParams layoutParams = new LinearLayout.LayoutParams(-2, -2);
            int ˊ = ˊ(context);
            if (i != SectionDetailSubHead.ॱॱ) {
                layoutParams.setMarginStart(ˊ);
            }
            textView.setLayoutParams(layoutParams);
            textView.setMaxLines(1);
            textView.setEllipsize(TruncateAt.END);
            textView.setGravity(17);
            textView.setTextSize(1, 16.0f);
        }

        protected int ˊ(Context context) {
            return context.getResources().getDimensionPixelSize(o.cab.c.ॱ);
        }

        void ˊ(int i) {
            if (i > 0) {
                this.ˏ.setMaxWidth(i);
            }
        }
    }

    public void setImmer(boolean z) {
        this.ˊॱ = z;
    }

    public void ˊ() {
        this.ˏ = false;
    }

    public SectionDetailSubHead(Context context) {
        super(context);
        ˊ(context);
    }

    public SectionDetailSubHead(Context context, @Nullable AttributeSet attributeSet) {
        super(context, attributeSet);
        ˊ(context);
    }

    public SectionDetailSubHead(Context context, @Nullable AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        ˊ(context);
    }

    public void setSpinnerClickLisenter(d dVar) {
        this.ˏॱ = dVar;
    }

    private void ˊ(Context context) {
        LayoutInflater from = LayoutInflater.from(context);
        this.ᐝ = getResources().getColor(b.ˎ);
        this.ʼ = getResources().getColor(b.ॱ);
        View inflate = from.inflate(ˏ(), this);
        this.ʽ = (LinearLayout) inflate.findViewById(e.ʾ);
        this.ˎ = (SectionDetailSpinner) inflate.findViewById(e.ˈ);
        this.ˎ.setOnItemSelectedListener(new 2(this));
        this.ˎ.setExtendClick(this);
    }

    protected int ˏ() {
        return i.ॱᐝ;
    }

    private int ˋ(Context context) {
        return ((azb.ॱ(context) - epv.ˋ(context, 96)) - (context.getResources().getDimensionPixelSize(o.cab.c.ॱ) * (this.ˊ.size() + 2))) / this.ˊ.size();
    }

    public void setTabHost(TabHost tabHost) {
        this.ॱˊ = tabHost;
    }

    public void ˎ(Context context, List<JGWTabInfo> list, boolean z, int i) {
        int ˋ;
        this.ˊ = list;
        if (z) {
            setMinimumHeight(context.getResources().getDimensionPixelSize(o.cab.c.ˏॱ));
        }
        this.ˋ.clear();
        this.ʽ.removeAllViews();
        if (this.ˊ.size() > 0) {
            ˋ = ˋ(context);
        } else {
            ˋ = 0;
        }
        for (int i2 = 0; i2 < this.ˊ.size(); i2++) {
            JGWTabInfo jGWTabInfo = (JGWTabInfo) this.ˊ.get(i2);
            c ˊ = ˊ(context, jGWTabInfo.ʼ(), jGWTabInfo.ᐝ(), i2);
            ˊ.ॱ().setOnClickListener(this);
            ˊ.ˊ(ˋ);
            this.ˋ.add(ˊ);
            this.ʽ.addView(ˊ.ॱ());
        }
        if (i < 0 || i >= this.ˋ.size()) {
            i = ॱॱ;
        }
        ˊ(i);
        for (ˋ = 0; ˋ < this.ˋ.size(); ˋ++) {
            if (ˋ != i) {
                ˏ((c) this.ˋ.get(ˋ), false);
            }
        }
        ˎ(i);
    }

    protected c ˊ(Context context, String str, String str2, int i) {
        return new c(context, str, str2, i);
    }

    private void ˏ(int i) {
        if (this.ʻ < this.ˋ.size()) {
            ((c) this.ˋ.get(this.ʻ)).ˋ(i);
        }
    }

    protected void ˎ(int i) {
        int i2 = 0;
        Options ˊ = ((JGWTabInfo) this.ˊ.get(i)).ˊ();
        if (ˊ != null) {
            String ˋ;
            Collection arrayList = new ArrayList();
            List ˎ = ˊ.ˎ();
            int ˋ2 = ((c) this.ˋ.get(i)).ˋ();
            if (ˋ2 == -1) {
                ˋ = cat.ˋ().ˋ(((JGWTabInfo) this.ˊ.get(i)).ʼ());
            } else {
                ˋ = null;
            }
            int i3 = 0;
            while (i2 < ˎ.size()) {
                OptionItem optionItem = (OptionItem) ˎ.get(i2);
                arrayList.add(optionItem.ˊ());
                if (optionItem.ˋ()) {
                    i3 = i2;
                }
                if (ˋ != null && ˋ.equals(optionItem.ˏ())) {
                    ˋ2 = i2;
                }
                i2++;
            }
            if (this.ॱ == null) {
                this.ॱ = new SpinnerAdapter(getContext(), arrayList);
                this.ˎ.setAdapter(this.ॱ);
                ˋ();
            } else {
                this.ॱ.clear();
                this.ॱ.addAll(arrayList);
            }
            this.ˏ = true;
            if (ˋ2 != -1) {
                this.ˎ.setSelection(ˋ2);
                return;
            } else {
                this.ˎ.setSelection(i3);
                return;
            }
        }
        this.ˎ.setVisibility(8);
    }

    protected void ˋ() {
        if (this.ˊॱ) {
            this.ॱ.setImmer(true);
            this.ॱ.setTextColor(this.ʼ);
            this.ˎ.setBackground(epo.ॱ(fo.ˊ(getContext(), o.cab.d.ॱˊ), this.ʼ));
        }
    }

    public void onClick(View view) {
        Object tag = view.getTag();
        if (tag instanceof c) {
            ˋ(((c) tag).ˊ());
        }
    }

    public void ˋ(int i) {
        ˊ(i);
        this.ॱˊ.setCurrentTab(i);
        ˎ(i);
    }

    private void ˊ(int i) {
        ˏ((c) this.ˋ.get(i), true);
        if (i != this.ʻ) {
            ˏ((c) this.ˋ.get(this.ʻ), false);
        }
        this.ʻ = i;
    }

    private void ˏ(c cVar, boolean z) {
        TextView ॱ = cVar.ॱ();
        if (z) {
            ॱ.setTextColor(this.ʼ);
            cjz.ˎ(ॱ);
            return;
        }
        ॱ.setTextColor(this.ᐝ);
        cjz.ˏ(ॱ);
    }

    public boolean onRenderReady(CSSViewProxy cSSViewProxy) {
        CSSRule rule = cSSViewProxy.getRule();
        if (rule.getStyleDeclaration() != null) {
            CSSValue propertyValue = rule.getStyleDeclaration().getPropertyValue(CSSPropertyName.BACKGROUND_TINT);
            if (propertyValue instanceof CSSMonoColor) {
                int color = ((CSSMonoColor) propertyValue).getColor();
                this.ᐝ = erq.ˊ(color, 0.75f);
                this.ʼ = color;
            }
        }
        return false;
    }

    public void setSelectedTextColor(int i) {
        this.ʼ = i;
    }

    public void setNormalTextColor(int i) {
        this.ᐝ = i;
    }
}
